package com.killuasy.utils.io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;


public class DownloadUtil {
	public static boolean DownloadFile(String downloadURL, String filePath){
		URL url = null;
		try {
			url = new URL(downloadURL);
		} catch (MalformedURLException e1) {
			e1.printStackTrace();
		}

		
		FileOutputStream fos = null;
		try {
			fos = new FileOutputStream(filePath);
		
		InputStream is = url.openStream();

		byte[] buffer = new byte[1024];
		int i = -1;
		while ((i = is.read(buffer)) != -1) {
			fos.write(buffer, 0, i);
		}
		
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			try {
				fos.flush();
				fos.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}


		return false;
	}
}
